<!-- 单选题 -->
<template>
  <form-item-wrapper :field="field">
    <el-radio-group v-model="field.answer" :disabled="field.disabled">
      <el-radio
        v-for="(item, index) in field.optionItems"
        :key="index"
        :label="item.value"
        @click.native.prevent="handleSelRadio(item)"
      >
        {{ item.label }}
      </el-radio>
    </el-radio-group>
  </form-item-wrapper>
</template>
<script lang="ts" setup>
import FormItemWrapper from "./form-item-wrapper.vue";
import { PropType } from "vue";
import QuestionType from "@bis/types/question";

const props = defineProps({
  field: Object as PropType<QuestionType>,
  colIdx: Number,
});

const emits = defineEmits<{
  (e: "answerChange", field, colIdx): void;
}>();

const handleSelRadio = (item) => {
  if (props.field.disabled) {
    return;
  }
  if (props.field.answer === item.value) {
    props.field.answer = "";
  } else {
    props.field.answer = item.value;
  }
  emits("answerChange", props.field, props.colIdx);
};
</script>
